package cn.stylefeng.guns.modular.hotgood.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.hotgood.entity.TaoIndexPic;
import cn.stylefeng.guns.modular.hotgood.mapper.TaoIndexPicMapper;
import cn.stylefeng.guns.modular.hotgood.model.params.TaoIndexPicParam;
import cn.stylefeng.guns.modular.hotgood.model.result.TaoIndexPicResult;
import  cn.stylefeng.guns.modular.hotgood.service.TaoIndexPicService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 轮播图（热门商品） 服务实现类
 * </p>
 *
 * @author lcw
 * @since 2019-09-27
 */
@Service
public class TaoIndexPicServiceImpl extends ServiceImpl<TaoIndexPicMapper, TaoIndexPic> implements TaoIndexPicService {

    @Resource
    private TaoIndexPicMapper taoIndexPicMapper;

    @Override
    public void add(TaoIndexPicParam param){
        TaoIndexPic entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(TaoIndexPicParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(TaoIndexPicParam param){
        TaoIndexPic oldEntity = getOldEntity(param);
        TaoIndexPic newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public TaoIndexPicResult findBySpec(TaoIndexPicParam param){
        return null;
    }

    @Override
    public List<TaoIndexPicResult> findListBySpec(TaoIndexPicParam param){
        return taoIndexPicMapper.customList(param);
    }

    @Override
    public LayuiPageInfo findPageBySpec(TaoIndexPicParam param){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }

    @Override
    public void addHotGood(String goodId) {
        taoIndexPicMapper.addHotGood(goodId);
    }

    @Override
    public void deletebygoodId(TaoIndexPicParam taoIndexPicParam) {
         taoIndexPicMapper.deletebygoodId(taoIndexPicParam);
    }

    private Serializable getKey(TaoIndexPicParam param){
        return null;
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private TaoIndexPic getOldEntity(TaoIndexPicParam param) {
        return this.getById(getKey(param));
    }

    private TaoIndexPic getEntity(TaoIndexPicParam param) {
        TaoIndexPic entity = new TaoIndexPic();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }


}
